#coding=utf-8
#Boa:Dialog:DlgSetProductSku

import wx

import PanelSkuSearch
from product import *

def create(parent, pro_id):
    return DlgSetProductSku(parent, pro_id)

[wxID_DLGSETPRODUCTSKU, wxID_DLGSETPRODUCTSKUBTN_CANCEL, 
 wxID_DLGSETPRODUCTSKUBTN_SAVE, 
] = [wx.NewId() for _init_ctrls in range(3)]

class DlgSetProductSku(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGSETPRODUCTSKU,
              name=u'DlgSetProductSku', parent=prnt, pos=wx.Point(297, 157),
              size=wx.Size(806, 272), style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u8bbe\u7f6eSKU')
        self.SetClientSize(wx.Size(790, 233))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.btn_save = wx.Button(id=wxID_DLGSETPRODUCTSKUBTN_SAVE,
              label=u'\u4fdd\u5b58', name=u'btn_save', parent=self,
              pos=wx.Point(232, 168), size=wx.Size(93, 26), style=0)
        self.btn_save.Bind(wx.EVT_BUTTON, self.OnBtn_saveButton,
              id=wxID_DLGSETPRODUCTSKUBTN_SAVE)

        self.btn_cancel = wx.Button(id=wxID_DLGSETPRODUCTSKUBTN_CANCEL,
              label=u'\u53d6\u6d88', name=u'btn_cancel', parent=self,
              pos=wx.Point(432, 168), size=wx.Size(93, 26), style=0)
        self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnBtn_cancelButton,
              id=wxID_DLGSETPRODUCTSKUBTN_CANCEL)

    def __init__(self, parent, pro_id):
        self._init_ctrls(parent)
        
        self.pro_id = pro_id
        proObj = CDataProduct.getInstance({'id':pro_id})
        self.panelSku = PanelSkuSearch.PanelSkuSearch(self, self)
        self.panelSku.SetSize(wx.Size(700, 100))
        self.panelSku.Move(wx.Point(5, 5))
        self.panelSku.set_category(proObj.getFieldVal('categoryId'))

    def OnBtn_saveButton(self, event):
    
        groups, items = self.panelSku.get_sku()
        if len(items) > 0:
            CDataProduct.change_sku(self.pro_id, items[0])            
        
        self.EndModal(wx.ID_OK)

    def OnBtn_cancelButton(self, event):
        self.EndModal(wx.ID_CANCEL)
